/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/reverse-linked-list
   @Language: C++
   @Datetime: 19-07-09 16:21
   */

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
	ListNode* reverseList(ListNode* head) {
		ListNode *p;
		for(p=NULL; head; swap(head,p))
			swap(p,head->next);
		return p;
	}
};
